package com.tubi.lambda1;

import java.util.Random;

public class test4lambda {
    public static void main(String[] args) {

        //内部类实现
        useRandomNumHandler(new RandomNumhandler() {
            @Override
            public int getNumber() {
                Random r =new Random();
                int num = r.nextInt(10)+1;
                return num;
            }
        });

        //lambda 实现
        useRandomNumHandler(()->{
            Random r =new Random();
            int num = r.nextInt(10)+1;
            return num;
        });
    }

    //方法
    public static void useRandomNumHandler(RandomNumhandler randomNumhandler){
        int result = randomNumhandler.getNumber();
        System.out.println(result);
    }
}

interface RandomNumhandler{
     int getNumber();
}